﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace GeneralDFS.BusinessLogical
{
    /// <summary>
    /// 主要负责dataNode本地对文件块的读取
    /// </summary>
    public class BlockReader
    {
        private FileStream fileStream;
        public BlockReader(Guid guid)
        {
            string blockPath = FSVolume.GetInstance().GetFilePath(guid);
            if (blockPath!=null)
                fileStream = new FileStream(blockPath, FileMode.Open, FileAccess.Read,FileShare.Read);
            else
            {
                LogUtil.LogError(string.Format("********Cannot Find Block:{0}******** /n********When InitBlockReader********",guid.ToString()));
            }
        }
        public int Read([In, Out] byte[] buff, int offset, int count)
        {
            int ReadLength = fileStream.Read(buff, offset, count);
            return ReadLength;
        }
        public void close()
        {
            fileStream.Close();
        }
    }
}
